package com.pixiv.controller;

import cn.hutool.json.JSONObject;
import com.pixiv.Entity.Commit;
import com.pixiv.Entity.User;
import com.pixiv.service.CommitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("commit")
public class CommitController {

    @Autowired
    private CommitService commitService;

    @ResponseBody
    @RequestMapping("getCommit")
    public String getCommit(HttpServletRequest req){
        HttpSession hs = req.getSession();
        User u = (User) hs.getAttribute("GLOBAL_USER_OBJECT");
        String uuid = (String) u.getVar().get_vector("GLOBAL_Title_UUID");
        List<Commit> list = commitService.getCommits(uuid);
        JSONObject jsonObject = new JSONObject();
        if (list.size() > 0)
            jsonObject.accumulate("flag",1);
        else
            jsonObject.accumulate("flag",0);
        jsonObject.accumulate("data",list);
        System.out.println(jsonObject.toString() );
        return jsonObject.toString();
    }

}
